Matplotlib Tutorial Part 07 - Loading Data from Files


In [10]:
%matplotlib inline
import matplotlib.pyplot as plt
import csv
import numpy as np
filename = "Matplotlib Tutorial Part 07 - Data"

CSV Method


In [11]:
fig = plt.figure(figsize=(17,9))

with open(filename) as csvfile:
    plots = csv.reader(csvfile,delimiter=',')
    X, Y = zip(*plots)

plt.plot(X,Y)        
        
plt.xlabel('x')
plt.ylabel('y')
plt.title('Data loaded with CSV Method')

# Pottling
plt.grid(True)
plt.show()


Numpy Method


In [12]:
fig = plt.figure(figsize=(17,9))

X, Y = np.loadtxt(filename,
                  delimiter=',',
                  unpack=True)

plt.plot(X,Y)        
        
plt.xlabel('x')
plt.ylabel('y')
plt.title('Data loaded with Numpy Method')

# Plotting
plt.grid(True)
plt.show()